package com.bmd.backgroundmanger.commons;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.bmd.backgroundmanger.entity.Question;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 题目导入监听器
 */
@Component
@Data
public class QuestionReadListener implements ReadListener<Question> {
    
    private List<Question> questions = new ArrayList<>();
    
    @Override
    public void invoke(Question question, AnalysisContext analysisContext) {
        // 每读取一行数据，都会调用这个方法
        questions.add(question);
    }
    
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        // 所有数据解析完成后调用
        System.out.println("题目数据读取完成，共读取" + questions.size() + "条数据");
    }
    
    /**
     * 清空数据
     */
    public void clear() {
        questions.clear();
    }
} 